package com.sh.high_grade_component;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SpinnerIconActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

    static final int[] iconArray = {
            R.drawable.one, R.drawable.two, R.drawable.three
    };

    static final String[] names = {"名字1", "名字2", "名字3",};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_spinner_icon);

//        findViewById(R.id.sp_icon)

        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < iconArray.length; i++) {
            Map<String, Object> objectObjectMap = new HashMap<>();
            objectObjectMap.put("icon", iconArray[i]);
            objectObjectMap.put("name", names[i]);
        }
//
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.item_simple, new String[]{"icon", "name"}, new int[]{R.id.iv_icon, R.id.tv_name});
        Spinner spinner = findViewById(R.id.sp_icon);
        spinner.setAdapter(simpleAdapter);
        spinner.setSelection(1);

        spinner.setOnItemSelectedListener(this);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this, "ok", R.id.iv_icon).show();
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
}